// pages/bankUser/bankUser.js
var app = getApp();
var com = require('../../common.js');
Page({
  data: {
    value: 0,
    bankInfo: [],
    state: '',
    mobile: '',
    priceBank: '',
    statusd: 1
  },
  onLoad: function(options) {
    var _this = this
    _this.onBanAccount();
    //获取银行开户列表
    _this.banShop()
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {},
  onBanAccount() {
    var _this = this
    com.link(app.link.accout, {}, function(rep) {
      console.log(rep);
      if (rep.data.state) {
        _this.setData({
          info: rep.data.response.info,
          state: true
        })
      } else {
        _this.setData({
          info: rep.data.response.info,
          state: false
        })
      }
    }, "GET")
  },
  //获取银行开户行
  banShop() {
    var _this = this
    com.link(app.link.banShop, {}, function(rep) {
      console.log(rep)
      var list = rep.data.response.bank
      console.log(list)
      _this.setData({
        bankInfo: list,
        statusd: 0
      })
      // list.map((v, k) => {
      //   console.log(v, k)
      // })
      // Object.keys(list).forEach((v, k) => {
      //   console.log(v,k)
      // })
    }, 'GET')
  },
  //提交按钮
  onUploadInfo() {
    var _this = this
    if (!_this.data.info.mobile) {
      wx.showToast({
        title: '请输入正确的手机号',
        icon: 'none'
      })
      return false;
    }
    var data = {
      mobile: _this.data.info.mobile,
      open_bank_code: _this.data.bankInfo[_this.data.value].key
    }
    com.link(app.link.accout, data, function(rep) {
      console.log(rep)
      if (rep.data.state) {
        wx.showModal({
          title: '提交成功',
          content: rep.data.message,
          showCancel: false,
          success(res) {
            if (res.confirm) {
              _this.onBanAccount()
              _this.setData({
                state: true
              })
            }
          }
        })
      } else {
        wx.showModal({
          content: rep.data.message,
          showCancel: false
        })
      }
    })
  },
  //获取输入的手机号
  onBindInput(e) {
    var _this = this,
      i = e.currentTarget.id,
      l = _this.data.info
    if (i == 4) {
      info.mobile = e.detail.value
      _this.setData({
        info: info
      })
    } else {
      _this.setData({
        priceBank: e.detail.value
      })
    }

  },
  //获取选中的开户行
  pickerBanner(e) {
    console.log(e)
    var _this = this,
      i = e.detail.value
    _this.setData({
      value: i
    })
  },
  //打款接口验证
  priceBank(e) {
    var _this = this,
      id = e.currentTarget.id
    if (id == 1) {
      if (_this.data.priceBank) {
        com.link(app.link.priceBank, {
          amount: _this.data.priceBank
        }, function(res) {
          console.log(res)
        })
      } else {
        wx.showToast({
          title: '请输入打款金额',
          icon: 'none'
        })
      }
    } else {
      _this.setData({
        state: false
      })
    }
  }
})